<?php
namespace App\Repositories\Backend;

use App\Models\Bottom;
use Illuminate\Support\Facades\Auth;

class ButtomRepository extends CommonRepository
{

    public function __construct(Bottom $bottomh)
    {
        parent::__construct($bottomh);
    }

    public function getLists($input)
    {
        $default_search = [
            'filter' => ['id', 'bottom_tel', 'bottom_address','bottom_time','bottom_QR_code'],
            'sort'   => [
                'created_at' => 'desc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->parseWheres($search)->paginate();
    }


    /**
     * 新增/修改
     * @param  array  $domains    参数数组
     * @param  int    $combo_id   套餐id
     * @return object
     */
    public function create($bottom_QR_code, $bottom_address, $bottom_tel, $bottom_time)
    {
        //先删除对应id的数据
        $result = $this->getDetail('1');

        if(!$result){
            $result = $this->model->create([
                'bottom_QR_code' => $bottom_QR_code,
                'bottom_address' => $bottom_address,
                'bottom_tel' => $bottom_tel,
                'bottom_time' => $bottom_time,
            ]);
        }else{
            $result = $this->model->where('id', '1')->update([
                'bottom_QR_code' => $bottom_QR_code,
                'bottom_address' => $bottom_address,
                'bottom_tel' => $bottom_tel,
                'bottom_time' => $bottom_time,
            ]);

        }

        return $result;
    }


}